package com.huika.renrench.control.main.epship.adap;

import java.util.HashMap;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.huika.renrench.R;
import com.huika.renrench.control.common.base.BaseAda;
import com.huika.renrench.control.main.epship.acty.EntrepreneurshipProjectActivity;

/**
 * @author chenyuan
 * @date：2015年6月2日,下午12:05:45
 * @describe:分类列表适配器
 */
public class EnClassifyAdapter extends BaseAda<HashMap<String, String>> {
	private static final String category_word = "行业分类";
	private static final String location_word = "所在地";
	private static final String key_word = "热门关键字";
	EntrepreneurshipProjectActivity acty=(EntrepreneurshipProjectActivity) mContext;
	
	/**
	 * @param context
	 */
	public EnClassifyAdapter(Context context) {
		super(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		ViewHolder holder;
		// View view = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_classify_project,
					parent, false);
			holder = new ViewHolder();
			holder.classify_name = (TextView) convertView
					.findViewById(R.id.classify_name);
			holder.has_select_icon = (ImageView) convertView
					.findViewById(R.id.has_select_icon);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		setDataFromNet(holder, position);

		return convertView;
	}

	/**
	 * @author cy
	 * @date 2015年6月2日,下午2:08:39
	 * @param holder
	 * @param position
	 */
	private void setDataFromNet(ViewHolder holder, int position) {
		
		// TODO Auto-generated method stub
			HashMap<String, String> map = getItem(position);
			if (!TextUtils.isEmpty(map.get("locationValue"))) {
				String typeName="locationValue";
				holder.classify_name.setText("" + map.get("locationValue"));
				setSelectItem(holder,position,typeName,acty.areaTv);
			}
			if (!TextUtils.isEmpty(map.get("categoryValue"))) {
				String typeName="categoryValue";
				holder.classify_name.setText("" + map.get("categoryValue"));
				setSelectItem(holder,position,typeName,acty.allTv);
			}
			if (!TextUtils.isEmpty(map.get("keyWordValue"))) {
				String typeName="keyWordValue";
				holder.classify_name.setText("" + map.get("keyWordValue"));
				setSelectItem(holder,position,typeName,acty.feesTv);
			}
	}

	public static class ViewHolder {
		/** 分类名称 */
		private TextView classify_name;
		private ImageView has_select_icon;
	}
	
	private void setSelectItem(ViewHolder holder, int position,String type,TextView textview){
		if (getItem(position).get(type).equals(textview.getText())) {
			holder.classify_name.setSelected(true);
			holder.has_select_icon.setVisibility(View.VISIBLE);
		} else {
			holder.classify_name.setSelected(false);
			holder.has_select_icon.setVisibility(View.GONE);
		}
	}

}
